import customerApi from '../../api/customer';
import orderApi from '../../api/order';
Page ({
  data: {
    payList: [],
    payIndex: null,
    qjList: [
      {
        name: '快递',
        id: 1,
      },
      {
        name: '上门取件',
        id: 2,
      },
    ],
    qjValue: '',
    payTypeList: [],
    payTypeObj: {
      1: '现付',
      2: '月结',
      3: '季度结',
      4: '余额支付',
    },
    pickMethod: '',

    minHour: 10,
    maxHour: 20,
    minDate: new Date ().getTime (),
    maxDate: new Date (2040, 10, 1).getTime (),
    currentDate: new Date ().getTime (),
    timeShow: false,
    takeTime: '',
    orderId: '',
  },
  onLoad (data) {
    console.log ('data00000x0x0000---->', data);
    let orderId = data.orderId;
    this.setData ({
      orderId,
    });
    this.getAddr ();
  },
  onUnload () {},
  getAddr () {
    customerApi.getAddr ().then (res => {
      let payType = res.payType || [];
      let list = [];
      payType.forEach (element => {
        list.push ({
          name: this.data.payTypeObj[element],
          id: element,
        });
      });
      let pickMethod = res.pickMethod;

      this.setData ({
        payTypeList: list,
        pickMethod,
      });
      console.log ('res----xx-->', res);
    });
  },

  orderBtn () {
    wx.login ({
      success (res) {
        if (res.code) {
          orderApi.orderPay(this.data.orderId, res).then (() => {
            // 发起请求，换取openId
            wx.requestPayment ({
              timeStamp: '',
              nonceStr: '',
              package: '',
              signType: 'MD5',
              paySign: '',
              success (res) {},
              fail (res) {},
            });
          });
        }
      },
    });

    // //下单
    // if(!this.data.skuid) {
    //   wx.showToast({ title: '必须选择膜', icon: 'none' });
    //   return
    // }
  },
  payTypePickerChange (e) {
    console.log ('e.detail---xx-->', e.detail);
    this.setData ({
      payTypeIndex: e.detail.value,
    });
  },
  pickMethodPickerChange (e) {
    console.log ('e.detail---xx-->', e.detail);
  },
  onInput (event) {
    this.setData ({
      currentDate: event.detail,
    });
  },
  takeYjBtn () {
    this.setData ({
      timeShow: true,
    });
    console.log ('去11----->');
  },
  onInput (event) {
    this.setData ({
      currentDate: event.detail,
    });
  },
  onClose () {
    this.setData ({
      timeShow: false,
    });
  },
  determineBtn () {
    this.onClose ();
    console.log ('------>', this.data.currentDate);
    this.takeTime = this.data.currentDate;

    let date = new Date (this.data.currentDate); // 参数需要毫秒数，所以这里将秒数乘于 1000
    let Y = date.getFullYear () + '-';
    let M =
      (date.getMonth () + 1 < 10
        ? '0' + (date.getMonth () + 1)
        : date.getMonth () + 1) + '-';
    let D = date.getDate () + ' ';
    let h = date.getHours () + ':';
    let m = date.getMinutes ();
    let time = Y + M + D + h + m;
    this.setData ({
      takeTime: time,
    });
  },
});
